<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>密语</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .summon_base64_str {
            background-color: #fff;
            min-width: 50%;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: center;
        }
        h1 {
            color: #333;
        }
        p {
            color: #666;
        }


        input[type="text"] {
            width: 80%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        button {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            background-color: #5cb85c;
            color: white;
            cursor: pointer;
        }
        button:hover {
            background-color: #4cae4c;
        }
        .show_base64_str {
            margin-top: 20px;
            font-size: 14px;
            color: #999;
        }

        .secret {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: left;
            min-width: 40%;
        }
        .secret h1 {
            color: blue;
        }
        .secret p {
            color: #666;
            line-break: auto;
            white-space: break-spaces;
            height: auto;
            width: 100%;
            word-break: break-all;
        }

        .url-container {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .url-container input[type="text"] {
            margin-right: 10px;
        }

    </style>
</head>
<body>
    {%if secret_string%}
    <div class="secret">
        <h1>密语</h1>
        <p>{{ secret_string }}</p>
    </div>
    {%else%}
    <div class="summon_base64_str">
        <h1>密语</h1>
        <p>请在下面输入密语：</p>
        <div style="text-align: left;">
            <div>
                <input type="text" id="secret_str_input">
                <button id="submit_btn">提交</button>
            </div>
            <div id="url_container">
                <input type="text" class="show_base64_str">
                <button id="copy_url" onclick="copyToClipboard">复制</button>
                <button id="urlto">跳转</button>
            </div>
        </div>
    </div>
    <script>
        function copyToClipboard() {
            var target=document.querySelector(".show_base64_str");
            target.select();
            document.execCommand("copy");
        }

        function utoa(str) {
            return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
                function toSolidBytes(match, p1) {
                    return String.fromCharCode('0x' + p1);
                }));
        }
    
        document.getElementById("submit_btn").onclick = function() {
            var secret_str = document.getElementById("secret_str_input").value;
            if (secret_str) {
                var base64_str = utoa(secret_str);
                root_url=window.location.origin+"/secret/";
                var url = root_url  + base64_str;
                document.querySelector(".show_base64_str").value = url;
            }
        };
    
        document.getElementById("urlto").onclick = function() {
            var secret_str = document.querySelector(".show_base64_str").value;
            if (secret_str) {
                window.location.href = secret_str;
            }
        }
    </script>
    
    {%endif%}

</body>

</html>